﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Atomic.Db;
using Atomic.FriendLinks.Entities;
using NHibernate.Linq;

namespace Atomic.FriendLinks.DAL
{
    /// <summary>
    /// 友情链接数据访问
    /// </summary>
    public class LinkDAL : BaseDAL<LinkEntity>
    {
        /// <summary>
        /// 重写按Sort排序的查询结果
        /// </summary>
        /// <param name="predicate">查询条件</param>
        /// <returns></returns>
        public override List<LinkEntity> GetList(System.Linq.Expressions.Expression<Func<LinkEntity, bool>> predicate = null)
        {
            //按是否具备搜索条件，进行不同的搜索
            if (null == predicate)
            {
                return session.Query<LinkEntity>()
                    .OrderBy(m=>m.Sort)
                    .ToList();
            }
            else
            {
                return session.Query<LinkEntity>()
                    .Where(predicate)
                    .OrderBy(m => m.Sort)
                    .ToList<LinkEntity>();
            }
        }
    }
}
